package com.example.sunsg.okhttptest.customview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.util.AttributeSet;

import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.view.SimpleDraweeView;

/**
 * Created by sunsg on 15/12/9.
 */
public class CircleImage extends SimpleDraweeView{
    public CircleImage(Context context, GenericDraweeHierarchy hierarchy) {
        super(context, hierarchy);
    }

    public CircleImage(Context context) {
        super(context);
    }

    public CircleImage(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CircleImage(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    Path mPath;
    int circle;
    @Override
    protected void onDraw(Canvas canvas) {
        if (circle == 0) {
            circle = Math.min(getWidth(), getHeight());
            mPath = new Path();
            mPath.addCircle(getWidth()/2, getHeight()/ 2, circle/2, Path.Direction.CW);
        }
        canvas.save();
        canvas.clipPath(mPath);
        super.onDraw(canvas);
        canvas.restore();
    }
}
